package com.relytosoft.mizar.media.display.api.pojo.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.relytosoft.dubhe.common.core.utils.BeanCopyUtils;
import com.relytosoft.mizar.media.display.api.entity.CruiseTrack;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;


/**
 * 巡航轨迹Dto
 *
 * @author hj
 * @version 1.0
 * @date 2022/4/26 15:56
 * @ClassName CruiseDto
 */
@ApiModel("巡航轨迹数据传输类")
public class CruiseTrackDto implements Serializable {

    private static final long serialVersionUID = 3879714745036289726L;

    /**
     * 主键ID
     */
    @TableId(value = "ID", type = IdType.AUTO)
    @ApiModelProperty(value = "主键ID")
    private Integer id;

    /**
     * 监控点/通道
     */
    @ApiModelProperty(value = "监控点/通道")
    @TableField("CHANNEL_ID")
    @NotNull(message = "监控点/通道不能为空")
    private Integer channelId;

    /**
     * 巡航名称
     */
    @ApiModelProperty(value = "巡航名称")
    @TableField("CRUISE_NAME")
    @NotBlank(message = "巡航名称不能为空")
    private String cruiseName;

    /**
     * 巡航索引
     */
    @ApiModelProperty(value = "巡航索引,范围[1,8]")
    @TableField("CRUISE_INDEX")
    @NotNull(message = "巡航索引不能为空")
    private Integer cruiseIndex;

    /**
     * 巡航预置点信息;json,预置点列表[{预置点索引，停留时间，云台速度},{}]
     */
    @ApiModelProperty(value = "巡航预置点信息;json,预置点列表[{预置点索引presetPointIndex，停留时间standingTime，云台速度speed},{}]")
    @TableField("CRUISE_PRESET")
    @NotNull(message = "预置点信息不能为空")
    private CruisePresetDto[] cruisePreset;


    @ApiModelProperty(value = "是否正在巡航")
    private boolean cruising;


    public CruiseTrackDto() {
    }

    public CruiseTrackDto(Integer cruiseIndex, Integer channelId) {
        this.cruiseIndex = cruiseIndex;
        this.cruiseName = cruiseIndex + "-巡航轨迹_" + cruiseIndex;
        this.channelId = channelId;
        this.cruising = false;
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getChannelId() {
        return channelId;
    }

    public void setChannelId(Integer channelId) {
        this.channelId = channelId;
    }

    public String getCruiseName() {
        return cruiseName;
    }

    public void setCruiseName(String cruiseName) {
        this.cruiseName = cruiseName;
    }

    public Integer getCruiseIndex() {
        return cruiseIndex;
    }

    public void setCruiseIndex(Integer cruiseIndex) {
        this.cruiseIndex = cruiseIndex;
    }

    public CruisePresetDto[] getCruisePreset() {
        return cruisePreset;
    }

    public void setCruisePreset(CruisePresetDto[] cruisePreset) {
        this.cruisePreset = cruisePreset;
    }

    public static CruiseTrackDto buildDto(CruiseTrack track) {
        CruiseTrackDto dto = new CruiseTrackDto();
        String preset = track.getCruisePreset();
        CruisePresetDto[] parse = JSONObject.parseArray(preset).parallelStream().map(j -> JSONObject.toJavaObject((JSON) j, CruisePresetDto.class)).toArray(CruisePresetDto[]::new);
        BeanCopyUtils.copy(track, dto);
        dto.setCruisePreset(parse);
        return dto;
    }

    public boolean isCruising() {
        return cruising;
    }

    public void setCruising(boolean cruising) {
        this.cruising = cruising;
    }

    public CruiseTrack build() {
        CruiseTrack track = new CruiseTrack();
        BeanUtils.copyProperties(this, track);
        track.setCruisePreset(JSON.toJSONString(this.getCruisePreset()));
        return track;
    }
}
